/*
 * mri_noise.h
 *
 *  Created on: Apr 16, 2009
 *      Author: alex
 */

#ifndef MRI_NOISE_H_
#define MRI_NOISE_H_

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <complex.h>

typedef struct {
	int size;
	float* data;
} mri_noise_cov_t;

/**
 * Generates a random number from a gaussian distribution with mean miu and stdev sigma
 */
float mri_noise_randn(float miu, float sigma);

/**
 * Returns total number of calls to the Gaussian RNG
 */
int mri_noise_ncalls();

/**
 * Generates a random number from a uniform distrribution in the [0,1) interval
 * using the  default generator
 */
float mri_noise_randu();

/**
 * Generates a gaussian noise vector of the specified size, mean and stdev
 *
 * NOTE: you need to explicitly free the allocated memory
 */
complex float* mri_noise_gen_gaussian(int size, float miu, float sigma);

/**
 * Loads a covariance matrix from the specified file.
 *
 * NOTE: you need to explicitly free the allocated memory
 */
mri_noise_cov_t* mri_noise_cov_read(FILE* f);

mri_noise_cov_t* mri_noise_cov_load(char* name);

/**
 * Generates a diagonal covariance matrix using the specified sigma
 *
 * NOTE: you need to explicitly free the allocated memory
 */
mri_noise_cov_t* mri_noise_cov_gen_diag(int size, float sigma);

/**
 * Frees the memory allocated for noise_cov
 */
void mri_noise_cov_free(mri_noise_cov_t* noise_cov);

/**
 * Computes (and allocates) the correlated noise vector
 * for a given covariance matrix
 *
 * NOTE: you need to explicitly free the allocated memory
 */
complex float* mri_noise_cov_get_instance(mri_noise_cov_t* noise_cov);

/**
 * Computes the correlated noise vector for a given covariance matrix
 * and writes it to noise_vector variable which *must* already be allocated
 */
void mri_noise_cov_fill_instance(complex float* noise_vector, mri_noise_cov_t* noise_cov);

#endif /* MRI_NOISE_H_ */
